package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjWorkModuleTypeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkModuleTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单模块分类表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-15
 */
@Api(tags = "工单模块分类接口")
@RestController
@RequestMapping("/work/moduleType")
public class ZjWorkModuleTypeController {
    @Resource
    private ZjWorkModuleTypeService workModuleTypeService;

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单模块-工单模块分类 - 新增或修改工单模块分类")
    @ApiOperation("新增或修改工单模块分类")
    @PostMapping("/{moduleId}/save")
    public Result save(HttpServletRequest request, @PathVariable @ApiParam(value = "模块ID", required = true) Long moduleId,
                       @RequestBody @Valid WorkModuleTypeVo moduleTypeVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workModuleTypeService.save(custAccId, moduleId, moduleTypeVo);
        return Result.success(null == moduleTypeVo.getId()? "新增模块分类成功" : "修改模块分类成功");
    }

    @ApiOperation("获取模块分类列表")
    @PostMapping("/{moduleId}/getList")
    public Result getList(@PathVariable @ApiParam(value = "模块ID", required = true) Long moduleId, @RequestBody SelectVo selectVo) {
        return Result.success("获取模块分类列表成功").data(workModuleTypeService.getList(moduleId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单模块分类 - 根据ID批量启用或禁用模块分类")
    @ApiOperation("根据ID批量启用或禁用模块分类")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "分类状态：false-启用，true-禁用") boolean status,
                          @RequestBody @ApiParam(value = "分类ID集合", required = true)List<Long> idList) {
        workModuleTypeService.updateDisabledBatchById(idList, status);
        return Result.success(status? "禁用模块分类成功" : "启用模块分类成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单模块分类 - 根据ID批量删除模块分类")
    @ApiOperation("根据ID批量删除模块分类")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "分类ID集合", required = true)List<Long> idList) {
        workModuleTypeService.deleteBatchById(idList);
        return Result.success("删除模块分类成功");
    }

}
